<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>ios仿射变换CGAffineTransform详解 | Albert Yuan's Blog</title><meta name="keywords" content="iOS,CoreAnimation"><meta name="author" content="Albert Yuan"><meta name="copyright" content="Albert Yuan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="referrer" content="no-referrer"><meta name="description" content="CGAffineTransform定义1234567&#x2F;&#x2F;平移 tx:控制x轴平移， ty：控制y轴平移&#x2F;&#x2F;缩放 a：控制x轴缩放， d：控制y轴缩放&#x2F;&#x2F;旋转 abcd共同控制struct CGAffineTransform &amp;#123;    CGFloat a, b, c, d;    CGFloat tx, ty;&amp;#125;;    UIView有CGAffineTransform类型的属性">
<meta property="og:type" content="article">
<meta property="og:title" content="ios仿射变换CGAffineTransform详解">
<meta property="og:url" content="https://yllove.gitee.io/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/index.html">
<meta property="og:site_name" content="Albert Yuan&#39;s Blog">
<meta property="og:description" content="CGAffineTransform定义1234567&#x2F;&#x2F;平移 tx:控制x轴平移， ty：控制y轴平移&#x2F;&#x2F;缩放 a：控制x轴缩放， d：控制y轴缩放&#x2F;&#x2F;旋转 abcd共同控制struct CGAffineTransform &amp;#123;    CGFloat a, b, c, d;    CGFloat tx, ty;&amp;#125;;    UIView有CGAffineTransform类型的属性">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://yllove.gitee.io/img/defaultCover.png">
<meta property="article:published_time" content="2021-10-21T07:30:03.948Z">
<meta property="article:modified_time" content="2022-06-10T10:04:22.959Z">
<meta property="article:author" content="Albert Yuan">
<meta property="article:tag" content="iOS">
<meta property="article:tag" content="CoreAnimation">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://yllove.gitee.io/img/defaultCover.png"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://yllove.gitee.io/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css" media="print" onload="this.media='all'"><script src="https://fastly.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js" defer></script><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: {"appId":"X8NS0XSX99","apiKey":"b9d4530647c8b5bf7928a04c47752ad7","indexName":"albertyuan","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://fastly.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://fastly.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://fastly.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://fastly.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://fastly.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'ios仿射变换CGAffineTransform详解',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2022-06-10 18:04:22'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/blog/atom.xml" title="Albert Yuan's Blog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/blog/img/favicon.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">155</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">56</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/img/defaultCover.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Albert Yuan's Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">ios仿射变换CGAffineTransform详解</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-21T07:30:03.948Z" title="发表于 2021-10-21 15:30:03">2021-10-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-06-10T10:04:22.959Z" title="更新于 2022-06-10 18:04:22">2022-06-10</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/iOS/">iOS</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/iOS/Animation%E5%8A%A8%E7%94%BB/">Animation动画</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="ios仿射变换CGAffineTransform详解"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h4 id="CGAffineTransform定义"><a href="#CGAffineTransform定义" class="headerlink" title="CGAffineTransform定义"></a>CGAffineTransform定义</h4><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//平移 tx:控制x轴平移， ty：控制y轴平移</span></span><br><span class="line"><span class="comment">//缩放 a：控制x轴缩放， d：控制y轴缩放</span></span><br><span class="line"><span class="comment">//旋转 abcd共同控制</span></span><br><span class="line"><span class="keyword">struct</span> <span class="built_in">CGAffineTransform</span> &#123;</span><br><span class="line">    <span class="built_in">CGFloat</span> a, b, c, d;</span><br><span class="line">    <span class="built_in">CGFloat</span> tx, ty;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<blockquote>
<p> UIView有CGAffineTransform类型的属性transform，它是定义在二维空间上完成View的     平移，     旋转，    缩放   等效果的实现</p>
</blockquote>
<p>初始化：</p>
<ol>
<li>CGAffineTransform  transform &#x3D; CGAffineTransformIdentity;  &#x2F;&#x2F;原型初始化方式</li>
</ol>
<blockquote>
<p>CGAffineTransformIdentity是系统提供的一个常量，&#x2F;* The identity transform: [ 1 0 0 1 0 0 ]. *&#x2F;（和原图一样的transform）;</p>
</blockquote>
<ol start="2">
<li>CGAffineTransform transform &#x3D; CGAffineTransformMake(CGFloat a,CGFloat b, CGFloat c,CGFloa td,CGFloat tx,CGFloat ty)  &#x2F;&#x2F;指定参数初始化方式</li>
</ol>
<p>   <strong>来解释下这里面参数的作用和变换的效果：</strong></p>
<p>   UIView原始的（默认的）transform：</p>
<p>   <img src= "" data-lazy-src="/blog/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/1.png"></p>
<p><img src= "" data-lazy-src="/blog/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/2.png"></p>
<p>再来看它的计算公式：3 X 3矩阵合成得到（x<code>，y</code>,1）:&#x2F;&#x2F;高等数学矩阵乘法</p>
<p><strong>注意：这里的x,y表示宽高</strong></p>
<p><img src= "" data-lazy-src="/blog/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/3.png"></p>
<p><img src= "" data-lazy-src="/blog/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/4.png"></p>
<p>新建工程，在widow上建立两个同样大小位置相同的View，第一个为沙色，第二个是浅海蓝色，我修改第二个View的transform中a的值为0.2：CGAffineTransformMake(0.2,0,0,1,0,0);</p>
<p><img src= "" data-lazy-src="/blog/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/5.png"></p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//用3秒动画完成变换，发现它是两边开始往中间缩小，打印View的frame原来的&#123;&#123;100，100&#125;，&#123;100，100&#125;&#125;变成了&#123;&#123;140，100&#125;，&#123;20，100&#125;&#125;。我们来计算下是不是根据公式计算的：</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//根据变换的transform我们知道第二个View的transform中 </span></span><br><span class="line">  </span><br><span class="line"><span class="comment">//transform变换参数： a = 0.2 , b = 0 , c = 0 , d = 1 , t.x = 0 , t.y = 0;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//原始的Size坐标：  x= 100 ,  y = 100</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//矩阵变化后的值</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//x` = ax + cy + t.x = 0.2 * 100 + 0 * 100 + 0 = 20</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//y` = bx+ dy + t.y = 0 * 100 + 1 * 100 + 0 = 100</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">- 结合上面的图和下面的计算，瞬间明白了这是x按照a值进行了比例缩放(以中心为参照)</span></span><br><span class="line"><span class="comment">- y按照d的值进行比列缩放</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">&gt; 最重要的是缩放的过程中View的position（中心点）是不会改变的</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">接着对b，c，t.x ，ty，进行深度研究发现:</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">- x会跟着c的值进行拉伸(View的宽度是跟着改变):出现倾斜效果</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">- y会跟着b的值进行拉伸（View的高度跟着改变）</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">- c和b的值改变不会影响到View的position（center中心点）的改变</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">- x会跟着t.x进行x做表平移，y会跟着t.y进行平移。这里的point（center）是跟着变换的</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  平移：</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  如果 c,b,d =0，a=1 那么 tx 就是图形按照x轴移动的距离，因此我们可以这样来表示x轴平移</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  &gt; CGAffineTransformMake(1,0,0,1,100,0) ;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  同理y轴平移的话</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  &gt; CGAffineTransformMake(1,0,0,1,0,100) ;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">再看缩放:如果b、d、tx、ty = 0，a 、d = 2,  那么新坐标x&#x27; = 2x，y&#x27; = 2y;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">&gt;  CGAffineTransformMake(2,0,0,2,0,0)</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<hr>
<h4 id="变换总结"><a href="#变换总结" class="headerlink" title="变换总结"></a>变换总结</h4><table>
<thead>
<tr>
<th><strong>变换类型</strong></th>
<th><strong>具体方式</strong></th>
<th>代码</th>
</tr>
</thead>
<tbody><tr>
<td>平移</td>
<td>根据本身的transform进行平移：</td>
<td>CGAffineTransformMakeTranslation(CGFloat tx,CGFloat ty)</td>
</tr>
<tr>
<td>tx，ty</td>
<td>根据本身的transform后者另外的transform进行平移：</td>
<td>CGAffineTransformTranslate(CGAffineTransform t,CGFloat tx,CGFloat ty)</td>
</tr>
<tr>
<td>缩放</td>
<td>根据本身的transform进行缩放 ：</td>
<td>CGAffineTransformMakeScale(CGFloat sx,CGFloat sy)</td>
</tr>
<tr>
<td>a, d</td>
<td>根据本身的transform后者另外的transform进行缩放</td>
<td>CGAffineTransformScale(CGAffineTransform t,CGFloat sx,CGFloat sy)</td>
</tr>
<tr>
<td>旋转</td>
<td>根据本身的transform进行旋转</td>
<td>CGAffineTransformMakeRotation(CGFloat angle) （angle 旋转的角度）</td>
</tr>
<tr>
<td></td>
<td>根据本身的transform后者另外的transform进行旋转</td>
<td>CGAffineTransformRotate(CGAffineTransform t,CGFloat angle)</td>
</tr>
<tr>
<td>反向旋转</td>
<td></td>
<td>CGAffineTransformInvert(CGAffineTransform t)</td>
</tr>
<tr>
<td><strong>合并</strong></td>
<td>两个transform合并起来</td>
<td>CGAffineTransformConcat(CGAffineTransform t1,CGAffineTransform t2)</td>
</tr>
</tbody></table>
<hr>
<p>苹果官方的建议，要多次使用transform，最好是初始化一个CGAffineTransform，进行多次操作。</p>
<hr>
<p>实际应用：</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//初始化</span></span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformIdentity</span>;</span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMake</span>(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//平移</span></span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMakeTranslation</span>(<span class="number">100</span>, <span class="number">100</span>);</span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMake</span>(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">100</span>, <span class="number">100</span>);</span><br><span class="line">    </span><br><span class="line"><span class="comment">//缩放</span></span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMakeScale</span>(<span class="number">.5</span>, <span class="number">.5</span>);</span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMake</span>(<span class="number">.5</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">.5</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    </span><br><span class="line"><span class="comment">//旋转</span></span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMakeRotation</span>(M_PI_4);</span><br><span class="line"><span class="keyword">self</span>.showView.transform = <span class="built_in">CGAffineTransformMake</span>(cos(M_PI_4), sin(M_PI_4), -sin(M_PI_4), cos(M_PI_4), <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p>源码分析：</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> CGAFFINETRANSFORM_H_</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CGAFFINETRANSFORM_H_</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransform</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;CoreGraphics/CGBase.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;CoreGraphics/CGGeometry.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="built_in">CF_IMPLICIT_BRIDGING_ENABLED</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//结构</span></span><br><span class="line"><span class="comment">//平移 tx:控制x轴平移， ty：控制y轴平移</span></span><br><span class="line"><span class="comment">//缩放 a：控制x轴缩放， d：控制y轴缩放</span></span><br><span class="line"><span class="comment">//旋转 abcd共同控制</span></span><br><span class="line"><span class="keyword">struct</span> <span class="built_in">CGAffineTransform</span> &#123;</span><br><span class="line">    <span class="built_in">CGFloat</span> a, b, c, d;</span><br><span class="line">    <span class="built_in">CGFloat</span> tx, ty;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* The identity transform: [ 1 0 0 1 0 0 ]. 常量（还原）和原图一样的transform*/</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="keyword">const</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformIdentity</span></span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* Return the transform [ a b c d tx ty ]. 创建transform*/</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformMake</span>(<span class="built_in">CGFloat</span> a, <span class="built_in">CGFloat</span> b,</span><br><span class="line">                                                  <span class="built_in">CGFloat</span> c, <span class="built_in">CGFloat</span> d, <span class="built_in">CGFloat</span> tx, <span class="built_in">CGFloat</span> ty)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 创建平移的transform: t&#x27; = [ 1 0 0 1 tx ty ]  */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformMakeTranslation</span>(<span class="built_in">CGFloat</span> tx,</span><br><span class="line">                                                             <span class="built_in">CGFloat</span> ty) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 创建缩放的transform: t&#x27; = [ sx 0 0 sy 0 0 ] */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformMakeScale</span>(<span class="built_in">CGFloat</span> sx, <span class="built_in">CGFloat</span> sy)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 创建旋转的（顺时针）transform: t&#x27; = [ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ] */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformMakeRotation</span>(<span class="built_in">CGFloat</span> angle)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 查看是否是默认的transform */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="type">bool</span> <span class="built_in">CGAffineTransformIsIdentity</span>(<span class="built_in">CGAffineTransform</span> t)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_4, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 根据已有的transform基础上进行平移: t&#x27; = [ 1 0 0 1 tx ty ] * t */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformTranslate</span>(<span class="built_in">CGAffineTransform</span> t,</span><br><span class="line">                                                       <span class="built_in">CGFloat</span> tx, <span class="built_in">CGFloat</span> ty) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 根据已有的transform基础上进行缩放: t&#x27; = [ sx 0 0 sy 0 0 ] * t */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformScale</span>(<span class="built_in">CGAffineTransform</span> t,</span><br><span class="line">                                                   <span class="built_in">CGFloat</span> sx, <span class="built_in">CGFloat</span> sy) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 根据已有的transform基础上进行旋转: t&#x27; =  [ cos(angle) sin(angle) -sin(angle) cos(angle) 0 0 ] * t */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformRotate</span>(<span class="built_in">CGAffineTransform</span> t,</span><br><span class="line">                                                    <span class="built_in">CGFloat</span> angle) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 反向旋转 */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformInvert</span>(<span class="built_in">CGAffineTransform</span> t)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 合并两个transform ：t&#x27; = t1 * t2 */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGAffineTransform</span> <span class="built_in">CGAffineTransformConcat</span>(<span class="built_in">CGAffineTransform</span> t1,</span><br><span class="line">                                                    <span class="built_in">CGAffineTransform</span> t2) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 判读两个transform是否相等 */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="type">bool</span> <span class="built_in">CGAffineTransformEqualToTransform</span>(<span class="built_in">CGAffineTransform</span> t1,</span><br><span class="line">                                                 <span class="built_in">CGAffineTransform</span> t2) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_4, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 得到新的中心:</span></span><br><span class="line"><span class="comment"> p&#x27; = p * t</span></span><br><span class="line"><span class="comment"> where p = [ x y 1 ]. */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGPoint</span> <span class="built_in">CGPointApplyAffineTransform</span>(<span class="built_in">CGPoint</span> point,</span><br><span class="line">                                              <span class="built_in">CGAffineTransform</span> t) <span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 得到新的size:</span></span><br><span class="line"><span class="comment"> s&#x27; = s * t</span></span><br><span class="line"><span class="comment"> where s = [ width height 0 ]. */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGSize</span> <span class="built_in">CGSizeApplyAffineTransform</span>(<span class="built_in">CGSize</span> size, <span class="built_in">CGAffineTransform</span> t)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_0, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 得到新的rect */</span></span><br><span class="line"><span class="built_in">CG_EXTERN</span> <span class="built_in">CGRect</span> <span class="built_in">CGRectApplyAffineTransform</span>(<span class="built_in">CGRect</span> rect, <span class="built_in">CGAffineTransform</span> t)</span><br><span class="line"><span class="built_in">CG_AVAILABLE_STARTING</span>(__MAC_10_4, __IPHONE_2_0);</span><br><span class="line"></span><br><span class="line"><span class="comment">/*** Definitions of inline functions. 内联函数定义***/</span></span><br><span class="line"><span class="built_in">CG_INLINE</span> <span class="built_in">CGAffineTransform</span></span><br><span class="line">__CGAffineTransformMake(<span class="built_in">CGFloat</span> a, <span class="built_in">CGFloat</span> b, <span class="built_in">CGFloat</span> c, <span class="built_in">CGFloat</span> d,</span><br><span class="line">                        <span class="built_in">CGFloat</span> tx, <span class="built_in">CGFloat</span> ty)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">CGAffineTransform</span> t;</span><br><span class="line">    t.a = a; t.b = b; t.c = c; t.d = d; t.tx = tx; t.ty = ty;</span><br><span class="line">    <span class="keyword">return</span> t;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CGAffineTransformMake __CGAffineTransformMake</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">CG_INLINE</span> <span class="built_in">CGPoint</span></span><br><span class="line">__CGPointApplyAffineTransform(<span class="built_in">CGPoint</span> point, <span class="built_in">CGAffineTransform</span> t)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">CGPoint</span> p;</span><br><span class="line">    p.x = (<span class="built_in">CGFloat</span>)((<span class="type">double</span>)t.a * point.x + (<span class="type">double</span>)t.c * point.y + t.tx);</span><br><span class="line">    p.y = (<span class="built_in">CGFloat</span>)((<span class="type">double</span>)t.b * point.x + (<span class="type">double</span>)t.d * point.y + t.ty);</span><br><span class="line">    <span class="keyword">return</span> p;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CGPointApplyAffineTransform __CGPointApplyAffineTransform</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">CG_INLINE</span> <span class="built_in">CGSize</span></span><br><span class="line">__CGSizeApplyAffineTransform(<span class="built_in">CGSize</span> size, <span class="built_in">CGAffineTransform</span> t)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">CGSize</span> s;</span><br><span class="line">    s.width = (<span class="built_in">CGFloat</span>)((<span class="type">double</span>)t.a * size.width + (<span class="type">double</span>)t.c * size.height);</span><br><span class="line">    s.height = (<span class="built_in">CGFloat</span>)((<span class="type">double</span>)t.b * size.width + (<span class="type">double</span>)t.d * size.height);</span><br><span class="line">    <span class="keyword">return</span> s;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> CGSizeApplyAffineTransform __CGSizeApplyAffineTransform</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">CF_IMPLICIT_BRIDGING_DISABLED</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span> <span class="comment">/* CGAFFINETRANSFORM_H_ */</span></span></span><br><span class="line">  </span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/xianfeng-zhang/p/7724042.html">应用参考：https://www.cnblogs.com/xianfeng-zhang/p/7724042.html</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Albert Yuan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://yllove.gitee.io/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/">https://yllove.gitee.io/2021/10/21/iOS%E5%8A%A8%E7%94%BB/ios%E4%BB%BF%E5%B0%84%E5%8F%98%E6%8D%A2CGAffineTransform%E8%AF%A6%E8%A7%A3/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://yllove.gitee.io" target="_blank">Albert Yuan's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/iOS/">iOS</a><a class="post-meta__tags" href="/blog/tags/CoreAnimation/">CoreAnimation</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/defaultCover.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://fastly.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2021/10/20/iOS/ios%E4%B8%AD%E7%9A%84static%E3%80%81extend/"><img class="prev-cover" src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="onerror=null;src='/blog/img/defaultCover.gif'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">ios中的static、extend</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/10/22/iOS%E5%8A%A8%E7%94%BB/ios%E5%8A%A8%E7%94%BB%E4%B9%8BFillMode%E8%AF%A6%E8%A7%A3/"><img class="next-cover" src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="onerror=null;src='/blog/img/defaultCover.gif'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">ios动画之FillMode详解</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2021/09/08/iOS动画/coreAnimation详解/" title="coreAnimation详解"><img class="cover" src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01afc6582c0ebba84a0d304f197129.gif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-08</div><div class="title">coreAnimation详解</div></div></a></div><div><a href="/blog/2021/10/22/iOS动画/ios动画之FillMode详解/" title="ios动画之FillMode详解"><img class="cover" src= "" data-lazy-src="/blog/img/defaultCover.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-22</div><div class="title">ios动画之FillMode详解</div></div></a></div><div><a href="/blog/2021/12/23/iOS动画/ios自定义转场动画实现/" title="ios自定义转场动画实现"><img class="cover" src= "" data-lazy-src="/blog/img/defaultCover.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-12-23</div><div class="title">ios自定义转场动画实现</div></div></a></div><div><a href="/blog/2021/08/20/iOS动画/使用CAReplicatorLayer实现动画效果/" title="使用CAReplicatorLayer实现动画效果"><img class="cover" src= "" data-lazy-src="http://t15.baidu.com/it/u=210535693,1610168828&fm=224&app=112&f=JPEG?w=500&h=375&s=2B61736E43F4BE7C1275A49A0200D083" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-20</div><div class="title">使用CAReplicatorLayer实现动画效果</div></div></a></div><div><a href="/blog/2021/08/09/iOS动画/核心动画01图层数/" title="iOS CoreAnimation(核心动画一)图层树Layer"><img class="cover" src= "" data-lazy-src="https://img-blog.csdnimg.cn/20201211222006630.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d1b3lvbmdtaW5nOTI1,size_16,color_FFFFFF,t_70" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-09</div><div class="title">iOS CoreAnimation(核心动画一)图层树Layer</div></div></a></div><div><a href="/blog/2021/08/09/iOS动画/核心动画02寄宿图/" title="iOS CoreAnimation(核心动画二)寄宿图：layer图层中包含的图"><img class="cover" src= "" data-lazy-src="https://i.iter01.com/images/6da777fd0dea0a56f9be2236a7a4e409e685a2169f54c6e9d704a466cf651d1e.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-09</div><div class="title">iOS CoreAnimation(核心动画二)寄宿图：layer图层中包含的图</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/blog/img/favicon.png" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Albert Yuan</div><div class="author-info__description">博学之,审问之,慎思之,明辨之,笃行之</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">155</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">56</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/yuanliangYL"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/yuanliangYL" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:yuanliangios@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="qq:1023817403" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">love cat , love life</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#CGAffineTransform%E5%AE%9A%E4%B9%89"><span class="toc-text">CGAffineTransform定义</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%98%E6%8D%A2%E6%80%BB%E7%BB%93"><span class="toc-text">变换总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/02/07/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E9%A1%B5%E4%B8%8B%E8%BD%BDIPA%E5%8C%85/" title="iOS 自定义网页下载IPA包"><img src= "" data-lazy-src="https://img.mp.itc.cn/upload/20170409/1a8f793d7282451cbd1beb6841608c90_th.jpeg" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="iOS 自定义网页下载IPA包"/></a><div class="content"><a class="title" href="/blog/2023/02/07/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS-%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E9%A1%B5%E4%B8%8B%E8%BD%BDIPA%E5%8C%85/" title="iOS 自定义网页下载IPA包">iOS 自定义网页下载IPA包</a><time datetime="2023-02-07T02:46:29.851Z" title="更新于 2023-02-07 10:46:29">2023-02-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/02/06/Flutter/Flutter%E6%8E%A5%E5%85%A5%E5%8E%9F%E7%94%9F-iOS/" title="flutter接入原生-iOS"><img src= "" data-lazy-src="https://pic4.zhimg.com/v2-6a115fea4db1ad770dccf4119bfab36f_1440w.jpg?source=172ae18b" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="flutter接入原生-iOS"/></a><div class="content"><a class="title" href="/blog/2023/02/06/Flutter/Flutter%E6%8E%A5%E5%85%A5%E5%8E%9F%E7%94%9F-iOS/" title="flutter接入原生-iOS">flutter接入原生-iOS</a><time datetime="2023-02-07T01:18:53.661Z" title="更新于 2023-02-07 09:18:53">2023-02-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/12/17/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS%20%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%AD%E5%AE%89%E8%A3%85APP/" title="iOS 如何在模拟器中安装APP"><img src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.winwin7.com%2Fuploadfile%2F2021%2F0114%2F20210114141748239.jpg&amp;refer=http%3A%2F%2Fwww.winwin7.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1673854539&amp;t=aad2108ffb799b04e94a28cc58f038f1" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="iOS 如何在模拟器中安装APP"/></a><div class="content"><a class="title" href="/blog/2022/12/17/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/iOS%20%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%AD%E5%AE%89%E8%A3%85APP/" title="iOS 如何在模拟器中安装APP">iOS 如何在模拟器中安装APP</a><time datetime="2022-12-17T07:48:56.594Z" title="更新于 2022-12-17 15:48:56">2022-12-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/08/05/Swift/swift%E5%B8%B8%E7%94%A8%E4%B8%89%E6%96%B9%E5%BA%93/" title="swift常用三方库"><img src= "" data-lazy-src="https://photos.infinum.com/store/b558bd40787ecad225d9c66322f14522" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="swift常用三方库"/></a><div class="content"><a class="title" href="/blog/2021/08/05/Swift/swift%E5%B8%B8%E7%94%A8%E4%B8%89%E6%96%B9%E5%BA%93/" title="swift常用三方库">swift常用三方库</a><time datetime="2022-12-16T06:37:20.115Z" title="更新于 2022-12-16 14:37:20">2022-12-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/12/12/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/GCD%E8%BF%9B%E9%98%B6%E4%B9%8BDispatchWorkItem%E5%92%8CDispatchGroup/" title="GCD进阶之DispatchWorkItem和DispatchGroup"><img src= "" data-lazy-src="/blog/img/defaultCover.png" onerror="this.onerror=null;this.src='/blog/img/defaultCover.gif'" alt="GCD进阶之DispatchWorkItem和DispatchGroup"/></a><div class="content"><a class="title" href="/blog/2022/12/12/iOS%E5%BC%80%E5%8F%91%E8%BF%9B%E9%98%B6/GCD%E8%BF%9B%E9%98%B6%E4%B9%8BDispatchWorkItem%E5%92%8CDispatchGroup/" title="GCD进阶之DispatchWorkItem和DispatchGroup">GCD进阶之DispatchWorkItem和DispatchGroup</a><time datetime="2022-12-12T07:19:37.277Z" title="更新于 2022-12-12 15:19:37">2022-12-12</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/blog/img/defaultCover.png')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Albert Yuan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcom to my  blog</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><div class="search-dialog__title" id="algolia-search-title">Algolia</div><div id="algolia-input-panel"><div id="algolia-search-input"></div></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-stats"></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://fastly.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/blog/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.2
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container:not\([display]\)').forEach(node => {
            const target = node.parentNode
            if (target.nodeName.toLowerCase() === 'li') {
              target.parentNode.classList.add('has-jax')
            } else {
              target.classList.add('has-jax')
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://fastly.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'REc8eytE1gJDl3d8FkudLNlL-gzGzoHsz',
      appKey: 'gGO3y8I9oVlc4Cd5N1fizNPW',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://fastly.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="255,0,0" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://fastly.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>